// YamlLanguagePackage.cs
//
// Copyright 2008 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace YaTools.Yaml.LanguagePackage
{
    [PackageRegistration(UseManagedResourcesOnly = true)]
    [InstalledProductRegistration(true, null, null, null)]
    [ProvideService(typeof (YamlLanguageService))]
    [ProvideLanguageExtension(typeof (YamlLanguageService), ".yaml")]
    [ProvideLanguageService(typeof (YamlLanguageService), "YAML", 0,
        CodeSense = true,
        CodeSenseDelay = 10,
        DefaultToInsertSpaces = true,
        EnableCommenting = true,
        MatchBraces = true,
        ShowCompletion = true,
        ShowMatchingBrace = true,
        AutoOutlining = true
        )]
    [Guid("B2DD6052-69DE-4220-9FBE-C039290F5746")]
    [ProvideLoadKey("Standard", "0.5.1212.0", "yatools.net YAML Language Support",
        "Intelligent Energy LLC, Woodinville, WA", 1)]
    public sealed class YamlLanguagePackage : Package, IVsInstalledProduct
    {
        public YamlLanguagePackage()
        {
            Debug.WriteLine("YamlLanguagePackage instantiated");
            IServiceContainer container = this;
            container.AddService(typeof (YamlLanguageService),
                                 new ServiceCreatorCallback(CreateYamlLanguageService), true);
        }

        #region IVsInstalledProduct Members

        int IVsInstalledProduct.IdBmpSplash(out uint pIdBmp)
        {
            // Note: this seems to never be used.   The ICON returned below controls what really happens.
            pIdBmp = 400;
            return VSConstants.S_OK;
        }

        int IVsInstalledProduct.IdIcoLogoForAboutbox(out uint pIdIco)
        {
            // This icon displays on both splash screen and about box 
            // (though at different sizes)

            pIdIco = 400;
            return VSConstants.S_OK;
        }

        int IVsInstalledProduct.OfficialName(out string pbstrName)
        {
            pbstrName = Resources.OfficialName;
            return VSConstants.S_OK;
        }

        int IVsInstalledProduct.ProductDetails(out string pbstrProductDetails)
        {
            pbstrProductDetails = Resources.ProductDetails;
            return VSConstants.S_OK;
        }

        int IVsInstalledProduct.ProductID(out string pbstrPID)
        {
            pbstrPID = Resources.ProductID;
            return VSConstants.S_OK;
        }

        #endregion

        private object CreateYamlLanguageService(
            IServiceContainer container,
            Type serviceType)
        {
            var result = new YamlLanguageService();
            result.SetSite(this);
            Debug.WriteLine("YamlLanguageService instantiated");
            return result;
        }
    }
}